//
// Created by Administrator on 2024/10/30.
//

#ifndef AI_PACS_ARCHIVEHANDLER_H
#define AI_PACS_ARCHIVEHANDLER_H

#include <iostream>
#include <stdexcept>
#include <format>
#include <nlohmann/json.hpp>
#include <CivetServer.h>
#include "../constant/shcma.h"
#include "../constant/JsonToStruct.h"
#include "../constant/dicomSchema.h"
#include "../processor/ResourcesProcessor.h"
#include "../processor/FileInstanceProcessor.h"
#include "../utils/CompressZip.h"
#include "../utils/FilesOperator.h"
#include "../utils/UuidGenerate.h"
#include "../utils/Downloader.h"
#include "../utils/DcmToolkit.h"
#include "../utils/AwsS3Client.h"
#include "../utils/DicomImage.h"
#include "../utils/JsonResponse.h"
#include "../utils/RequestJson.h"
#include "../utils/log.h"
#include "../constant/ArchiveEnumStatus.h"



using json = nlohmann::json;

class ArchiveHandler : public CivetHandler {
public:
    bool handlePost(CivetServer *server, struct mg_connection *conn) override;

    std::string archive_dicom(ArchiveReq &req);

    static void create_archive_record(ArchiveReq &req);

    static bool verify_file_instance(ArchiveReq &req);

    static std::string archive_instances(ArchiveReq &req);

    static  std::vector<std::string> archive_download(std::vector<std::string> &files,std::string  &fileType,std::string &requestIdPtah);

    static std::vector<std::map<std::string,std::string>> read_dicom_file(std::vector<std::string> &files,std::string &hospCode);

    static void archive_upload(std::vector<std::map<std::string,std::string>> &images);

    static DicomStudy aggregate_result(std::vector<std::map<std::string,std::string>> &images);

    static void send_app_json_object_storage(const std::string &prefix,const DicomStudy& study);

    static void create_file_instance(const DicomStudy& study);

    static  void update_archive_record(const DicomArchive &arc);
};


#endif //AI_PACS_ARCHIVEHANDLER_H
